package com.dyz.leetcode._13_binaryTree;

import com.dyz.leetcode.TreeNode;

public class _543_diameterOfBinaryTree {
    private int ans=0;
    public int diameterOfBinaryTree(TreeNode root) {
        if(root==null){return 0;}
        maxDepth(root);
        return ans;
    }
    public int maxDepth(TreeNode root) {
        if(root==null){return 0;}
        int left = maxDepth(root.left);
        int right = maxDepth(root.right);
        ans = Math.max(ans, left+right);
        return Math.max(left,right)+1;
    }
}
